package com.lfd.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lfd.service.ProductHotService;
import com.lfd.util.Result;
import com.lfd.vo.ProductVo;

import sun.util.logging.resources.logging;

@Controller
@RequestMapping("/reproduct")
public class ProductHotController {

	private final Logger logger = Logger.getLogger(ProductHotController.class);
	@Autowired
	private ProductHotService productHotService;
 
	@ResponseBody
	@RequestMapping("/re")
	public Result ReProduct(ProductVo productVo, @RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit) {
		List<ProductVo> reProduct = new ArrayList();
		try {
			reProduct = productHotService.ReProduct(productVo, page, limit);
		} catch (Exception e) {
			logger.error("失败", e);
			return new Result("1", "失败");
		}
		return new Result("0", "成功", 100, reProduct);

	}

	/**
	 * 取消热门商品
	 * 
	 * @param productVo
	 * @return
	 */

	@ResponseBody
	@RequestMapping("/update")
	public Result update(@RequestParam("ids") List<Long> ids) {
		try {
			productHotService.update(ids);
		} catch (Exception e) {
			logger.error("失败", e);
			return new Result("1", "失败");
		}
		return new Result("0", "成功");

	}

	/**
	 * 设置热门
	 * 
	 * @param ids
	 * @param isremen
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/szremen")
	public Result szremen(@RequestParam("ids") List<Long> ids, @RequestParam("isremen") Boolean isremen) {
		try {
			productHotService.szremen(ids, isremen);
		} catch (Exception e) {
			logger.error("失败", e);
			return new Result("1", "失败");
		}

		return new Result("0", "成功");

	}
}
